package hr_project.hr.web;

import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import hr_project.hr.dao.IJob_release;
import hr_project.hr.entity.Emp;
import hr_project.hr.entity.Job_release;

@Controller
@RequestMapping("/job")
public class Job_releaseAction {
	@Autowired
	private IJob_release biz;

	
	public IJob_release getBiz() {
		return biz;
	}


	public void setBiz(IJob_release biz) {
		this.biz = biz;
	}


	/*@RequestMapping("/addjob")
	public String addJob(Job_release job,HttpSession sess){
		Emp emp=(Emp)sess.getAttribute("loger");
		//工作名，招聘人数数量，职位描述，职位要求
		//System.out.println("部门id"+emp.getUs_depid().getDe_id());
		job.setDeptid(emp.getUs_depid());
		job.setPublisher(emp);
		//System.out.println("部门经理"+emp.getUs_id());
		
		biz.addJobInfo(job);
		
		return "<script>history.go(-1);</script>";
	} */
	@RequestMapping("/addjob")
	public String addJob(Job_release job,HttpSession sess){
		Emp emp=(Emp)sess.getAttribute("loger");
		//工作名，招聘人数数量，职位描述，职位要求
		//System.out.println("部门id"+emp.getUs_depid().getDe_id());
		job.setDeptid(emp.getUs_depid());
		job.setPublisher(emp);
		//System.out.println("部门经理"+emp.getUs_id());
		
		biz.addJobInfo(job);
		
		return "job-mylist";
	} 
	//审核列表
	@RequestMapping("/list")
	@ResponseBody
	public List<Job_release> getlist(){
		return biz.getChecked();
	}
	
	//对于申请部门加人审核 getbyid展示申请的信息
	@RequestMapping("/getbyid")
	public ModelAndView getByid(@RequestParam(defaultValue="0")int n,long id,ModelAndView mv){
		Job_release job=biz.getByid(id);
		mv.addObject("job", job);
		if(n==0){
			//审核的模态框
			mv.setViewName("apply-job");
		}
		else if(n==1)
		{
			//查看详情
			System.out.println(job.getDealtime());
			System.out.println(job.getDealevent());
			mv.setViewName("show-jobmylist");
			
		}
		else if(n==2)
		{
			//删除改变状态
			Job_release job2=new Job_release();
			job2.setStatus("已删除");
			job2.setId(id);
			biz.modJob_release(job2);
			mv.setViewName("job-mylist");
		}
		return mv;
	} 
	
	/**
	 * 对于申请部门加人进行审核 审核之后跳转到审核列表界面
	 * --结束时间，处理人，处理结果事由，处理时间
	 * 还要进行结果的判断，如果通过才会有截至时间，不通过就没有
	 * */
	@RequestMapping("/mod")
	public String update(HttpSession sess,Job_release job){
		Emp emp=(Emp)sess.getAttribute("loger");
		job.setDealempid(emp);
		job.setDealtime(new Date());
		if(job.getStatus().equals("通过")){
			long time=(new Date().getTime())+(7*24*60*60*1000);
			job.setEndtime(new Date(time));
		}
		biz.modJob_release(job);
		return "job-list";
	}
	
	@RequestMapping("/mylist")
	@ResponseBody
	public List<Job_release> getjobByuid(HttpSession sess){
		Emp emp=(Emp)sess.getAttribute("loger");
		return biz.getjobByuid(emp.getUs_id());
	}
	

}
